import axios from 'axios'
import Qs from 'qs'

var def = axios.create({
    // 本地
    // baseURL: 'http://public.com/admin/',
    // 测试服务器
    baseURL: 'http://welfare.llf360.com/admin/',
    headers: {
        // 'X-Requested-With': 'XMLHttpRequest',
        'Content-Type': 'application/x-www-form-urlencoded'
    },
});
// 登陆接口
var __login = {
    postLogin: (data) => {
        return def({
            url: 'login',
            method: 'post',
            data: data,
            transformRequest: [function (data) {
                // 对 data 进行任意转换处理
                // 方法一
                // let ret = ''
                // for (let it in data) {
                //     ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
                // }
                // return ret

                // 方法二
                return Qs.stringify(data)
            }],
        })
    }
}

//信息管理
var __msg = {
    // 列表
    List: (data) => {
        return def({
            url: `message/list?token=${localStorage.getItem('TOKEN')}`,
            method: 'get',
            params: data,
            paramsSerializer: function (params) {
                return Qs.stringify(params, { arrayFormat: 'brackets' })
            },
        })
    },
    // 详情
    detail: (data) => {
        return def({
            url: `message/detail?token=${localStorage.getItem('TOKEN')}`,
            method: 'post',
            data: data,
            transformRequest: [function (data) {
                return Qs.stringify(data)
            }],
        })
    },
    // 新增
    add: (data) => {
        return def({
            url: `message/add?token=${localStorage.getItem('TOKEN')}`,
            method: 'post',
            data: data,
            transformRequest: [function (data) {
                return Qs.stringify(data)
            }],
        })
    },
    // 修改
    edit: (data) => {
        return def({
            url: `message/edit?token=${localStorage.getItem('TOKEN')}`,
            method: 'post',
            data: data,
            transformRequest: [function (data) {
                return Qs.stringify(data)
            }],
        })
    },
    // 删除
    del: (data) => {
        return def({
            url: `message/del?token=${localStorage.getItem('TOKEN')}`,
            method: 'post',
            data: data,
            transformRequest: [function (data) {
                return Qs.stringify(data)
            }],
        })
    }
}
//会员管理
var __vip = {
    // 列表
    List: (data) => {
        return def({
            url: `userinfo/list?token=${localStorage.getItem('TOKEN')}`,
            method: 'get',
            params: data,
            paramsSerializer: function (params) {
                return Qs.stringify(params, { arrayFormat: 'brackets' })
            },
        })
    },
    // 会员下级人员详情
    subordinatedetail: (data) => {
        return def({
            url: `userinfo/subordinatedetail?token=${localStorage.getItem('TOKEN')}`,
            method: 'post',
            data: data,
            transformRequest: [function (data) {
                return Qs.stringify(data)
            }],
        })
    },
    // 会员捐款详情
    projectdetail: (data) => {
        return def({
            url: `userinfo/projectdetail?token=${localStorage.getItem('TOKEN')}`,
            method: 'post',
            data: data,
            transformRequest: [function (data) {
                return Qs.stringify(data)
            }],
        })
    },
}
// 客户反馈
var __feedback = {
    // 列表
    List: (data) => {
        return def({
            url: `feedback/list?token=${localStorage.getItem('TOKEN')}`,
            method: 'get',
            params: data,
            paramsSerializer: function (params) {
                return Qs.stringify(params, { arrayFormat: 'brackets' })
            },
        })
    },
    // 查看反馈问题
    edit: (data) => {
        return def({
            url: `feedback/edit?token=${localStorage.getItem('TOKEN')}`,
            method: 'post',
            data: data,
            transformRequest: [function (data) {
                return Qs.stringify(data)
            }],
        })
    },
}
// 捐赠项目管理
var __donate = {
    List: (data) => {
        return def({
            url: `item/list?token=${localStorage.getItem('TOKEN')}`,
            method: 'get',
            params: data,
            paramsSerializer: function (params) {
                return Qs.stringify(params, { arrayFormat: 'brackets' })
            },
        })
    },
    // 上传项目图片
    upload: (data) => {
        return def({
            url: `item/uploadvideo?token=${localStorage.getItem('TOKEN')}`,
            method: 'post',
            data: data,
            transformRequest: [function (data) {
                return Qs.stringify(data)
            }],
        })
    },
    // 新增
    add: (data) => {
        return def({
            url: `item/add?token=${localStorage.getItem('TOKEN')}`,
            method: 'post',
            data: data,
            transformRequest: [function (data) {
                return Qs.stringify(data)
            }],
        })
    },
    // 修改
    edit: (data) => {
        return def({
            url: `item/edit?token=${localStorage.getItem('TOKEN')}`,
            method: 'post',
            data: data,
            transformRequest: [function (data) {
                return Qs.stringify(data)
            }],
        })
    },
    // 删除
    del: (data) => {
        return def({
            url: `item/del?token=${localStorage.getItem('TOKEN')}`,
            method: 'post',
            data: data,
            transformRequest: [function (data) {
                return Qs.stringify(data)
            }],
        })
    }
}
// 捐赠品管理
var __donation = {
    List: (data) => {
        return def({
            url: `donate/list?token=${localStorage.getItem('TOKEN')}`,
            method: 'get',
            params: data,
            paramsSerializer: function (params) {
                return Qs.stringify(params, { arrayFormat: 'brackets' })
            },
        })
    },
    // 上传项目图片
    upload: (data) => {
        return def({
            url: `item/uploadvideo?token=${localStorage.getItem('TOKEN')}`,
            method: 'post',
            data: data,
            transformRequest: [function (data) {
                return Qs.stringify(data)
            }],
        })
    },
    // 新增
    add: (data) => {
        return def({
            url: `donate/add?token=${localStorage.getItem('TOKEN')}`,
            method: 'post',
            data: data,
            transformRequest: [function (data) {
                return Qs.stringify(data)
            }],
        })
    },
    // 修改
    edit: (data) => {
        return def({
            url: `donate/edit?token=${localStorage.getItem('TOKEN')}`,
            method: 'post',
            data: data,
            transformRequest: [function (data) {
                return Qs.stringify(data)
            }],
        })
    },
    // 删除
    del: (data) => {
        return def({
            url: `donate/del?token=${localStorage.getItem('TOKEN')}`,
            method: 'post',
            data: data,
            transformRequest: [function (data) {
                return Qs.stringify(data)
            }],
        })
    }
}

// 捐赠项目反馈管理
var __itemfeedback = {
    List: (data) => {
        return def({
            url: `itemfeedback/list?token=${localStorage.getItem('TOKEN')}`,
            method: 'post',
            data: data,
            transformRequest: [function (data) {
                return Qs.stringify(data)
            }],
        })
    },
    // 新增
    add: (data) => {
        return def({
            url: `itemfeedback/add?token=${localStorage.getItem('TOKEN')}`,
            method: 'post',
            data: data,
            transformRequest: [function (data) {
                return Qs.stringify(data)
            }],
        })
    },
    // 修改
    edit: (data) => {
        return def({
            url: `itemfeedback/edit?token=${localStorage.getItem('TOKEN')}`,
            method: 'post',
            data: data,
            transformRequest: [function (data) {
                return Qs.stringify(data)
            }],
        })
    },
    // 删除
    del: (data) => {
        return def({
            url: `itemfeedback/del?token=${localStorage.getItem('TOKEN')}`,
            method: 'post',
            data: data,
            transformRequest: [function (data) {
                return Qs.stringify(data)
            }],
        })
    }
}
// 订单列表
var __order = {
    List: (data) => {
        return def({
            url: `order/list?token=${localStorage.getItem('TOKEN')}`,
            method: 'get',
            params: data,
            paramsSerializer: function (params) {
                return Qs.stringify(params, { arrayFormat: 'brackets' })
            },
        })
    },
}

export default { __login, __order,__msg,__donate,__vip,__feedback,__donation,__itemfeedback}